import Vue from 'vue'
import App from './App.vue'
import router from './router' //引入
import constant from './utils/constant.js' //引入
import {
	isAndroid
} from './utils/utils' //引入
import wx from 'weixin-js-sdk'
//引入vconsole
import vConsole from 'vconsole'

//引入weui
import weui from 'weui.js'
import 'weui'
import $ from 'jquery'
Vue.prototype.$ = $;
import moment from 'moment'
Vue.prototype.$moment = moment
//全局隐藏非功能性按钮	
wx.hideAllNonBaseMenuItem();

Vue.prototype.$weui = weui
Vue.prototype.$wx = wx;
Vue.prototype.$vConsole = new vConsole()

import {
	registryToast,
	registryLoadingToast,
	registryHideLoadingToast
} from './toast/index'
import {
	getToken,
	setToken
} from '@/utils/auth' // 验权(从cookie中获取)

Vue.use(registryToast)
Vue.use(registryLoadingToast)
Vue.use(registryHideLoadingToast)

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
	debugger
	document.title = to.meta.title
	let url = to.path;
	if(constant.GETWXJSTICKERURLS.indexOf(url)>=0 && !localStorage.getItem(url)) {
		console.log("setItem 1 from url:"+url)
		localStorage.setItem(url,1);
	}
	next()
	//   // 点击登录时，拿到了token并存入了cookie,保证页面刷新时,始终可以拿到token
	//   if (getToken('token') ) {
	// if(path.indexOf("tech")>=0 &&path.indexOf("techManagerMain")<0 ) {
	//  next("/techManagerMain")
	// } else {
	//  next() 
	// }
	//   } else {
	// // if (to.path.indexOf("/techLogin")<0){
	//  next()
	// // } else {
	//  // next('/techLogin')
	// // }
	// // if(window.location.host.indexOf('localhost')>-1||window.location.host.indexOf('127.0.0.1')>-1){

	// // } else{
	//  // //判断是用户还是员工
	//  // let url="";
	//  // if(to.path.indexOf("tech")>-1){
	//  // 		   //员工登录界面
	// 	// url=window.location.protocol+'//'+window.location.host+'/tech/login';
	//  // } else{
	//  // 		   //客户登录
	//  // 		   url=window.location.protocol+'//'+window.location.host+'/tech/login';
	//  // }
	//  //  console.log(url)
	//  // 		window.location.href=url;
	// // }

	//   }
})
router.afterEach((to, from, next) => {
	debugger
	let path = to.path;
	if (!isAndroid()) { // 非ios设备，切换路由时候进行重新签名
		// ios设备，需要强制刷新一次页面进行重新签名
		if (constant.GETWXJSTICKERURLS.indexOf(path)>=0 && localStorage.getItem(path)== 1) {
			console.log("reload")
			//存儲當前URL
			window.entryUrl = to.path;
			console.log("setItem 2")
			localStorage.setItem(path,2)
			window.location.replace(to.fullPath)
		}
	}
})
new Vue({
	router,
	render: h => h(App),
}).$mount('#app')
